/// @tags: SegmentTree TreeInTree BIT
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <stack>
#define rint register int

using std::cin;
using std::cout;

namespace BlueQuantum {

typedef long long LL;

constexpr int maxn = 2e5 + 3, segn = maxn * 200;

int n, segcnt;
int a[maxn], ls[segn], rs[segn];
int sum[segn];
std::stack<int> stk;

inline int lowbit(int x) { return x & -x; }

inline void destory(int &u) {
  sum[u] = ls[u] = rs[u] = 0;
  stk.push(u);
  u = 0;
}

inline int allocate() {
  if (stk.empty()) return ++segcnt;
  int res = stk.top();
  stk.pop();
  return res;
}

void modify(int &u, int l, int r, int pos, int val) {
  if (u == 0) u = allocate();
  sum[u] += val;
  if (l == r) {
    if (sum[u] == 0) destory(u);
    return;
  }
  int mid = (l + r) >> 1;
  pos <= mid ? modify(ls[u], l, mid, pos, val) : modify(rs[u], mid + 1, r, pos, val);
  if (sum[u] == 0) destory(u);
}

LL query(int u, int l, int r, int L, int R) {
  if (u == 0) return 0;
  if (L <= l && r <= R) return sum[u];
  int mid = (l + r) >> 1;
  LL res = 0;
  if (L <= mid) res += query(ls[u], l, mid, L, R);
  if (mid < R) res += query(rs[u], mid + 1, r, L, R);
  return res;
}

int root[maxn];

inline void modify(int pos, int val, int opt) {
  while (pos <= n) {
    modify(root[pos], 1, n, val, opt);
    pos += lowbit(pos);
  }
}

inline LL query(int l, int r, int L, int R) {
  LL res = 0;
  if (L > R) return 0;
  while (r) {
    res += query(root[r], 1, n, L, R);
    r -= lowbit(r);
  }
  l--;
  if (l)
    while (l) {
      res -= query(root[l], 1, n, L, R);
      l -= lowbit(l);
    }
  return res;
}

inline int main() {
  int q;
  cin >> n >> q;
  LL ans = 0;
  for (int i = 1; i <= n; ++i) modify(i, i, 1), a[i] = i;
  while (q--) {
    int l, r;
    cin >> l >> r;
    if (l == r) {
      cout << ans << '\n';
      continue;
    }
    if (l > r) std::swap(l, r);
    int L = a[l], R = a[r], max = std::max(L, R), min = std::min(L, R);
    a[l] < a[r] ? ans++ : ans--;
    ans += (min == L ? 2 : -2) * query(l, r, min + 1, max - 1);
    modify(l, a[l], -1);
    modify(r, a[r], -1);
    modify(l, a[r], 1);
    modify(r, a[l], 1);
    std::swap(a[l], a[r]);
    cout << ans << '\n';
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("CF785E Anton and Permutation.in", "r", stdin);
  freopen("CF785E Anton and Permutation.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
